package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Scanner;

/**
 * 调用有参的方法
 */
public class ReflectDemo5 {
    public static void main(String[] args) throws Exception {
        //

        Class cls=Class.forName("reflect.Person");
        Object obj=cls.newInstance();
        Method method=cls.getMethod("say", String.class);
        method.invoke(obj,"hello ooo!");

        Method method1=cls.getMethod("say", String.class, int.class);
        method1.invoke(obj,"hello 222!",6);
        System.out.println("-----------------------------------");



        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个类名：");
        String className=scan.nextLine();
        System.out.println("请输入一个方法名：");
        String methodName=scan.nextLine();
        System.out.println("请输入参数1 方式的消息");
        String msg=scan.nextLine();
        System.out.println("请输入参数2 的数字执行多少次");
        int num=scan.nextInt();
        Class cls2=Class.forName(className);
        Constructor c2=cls2.getConstructor();
        Object obj2=cls2.newInstance();
        Method method2=cls2.getMethod(methodName,String.class,int.class);
        method2.invoke(obj2,msg,num);


    }
}
